package org.esgi.server.dns.message;

public class Header {
	    int id;
	    boolean qr;
	    int opcode;
	    boolean aa;
	    boolean tc;
	    boolean rd;
	    boolean ra;
	    int z;
	    int rcode;
	    int qdcount;
	    int ancount;
	    int nscount;
	    int arcount;

	    public boolean isAa() {
	        return aa;
	    }

	    public void setAa(boolean aa) {
	        this.aa = aa;
	    }

	    public int getAncount() {
	        return ancount;
	    }

	    public void setAncount(int ancount) {
	        this.ancount = ancount;
	    }

	    public int getArcount() {
	        return arcount;
	    }

	    public void setArcount(int arcount) {
	        this.arcount = arcount;
	    }

	    public int getId() {
	        return id;
	    }

	    public void setId(int id) {
	        this.id = id;
	    }

	    public int getNscount() {
	        return nscount;
	    }

	    public void setNscount(int nscount) {
	        this.nscount = nscount;
	    }

	    public int getOpcode() {
	        return opcode;
	    }

	    public void setOpcode(int opcode) {
	        this.opcode = opcode;
	    }

	    public int getQdcount() {
	        return qdcount;
	    }

	    public void setQdcount(int qdcount) {
	        this.qdcount = qdcount;
	    }

	    public boolean isQr() {
	        return qr;
	    }

	    public void setQr(boolean qr) {
	        this.qr = qr;
	    }

	    public boolean isRa() {
	        return ra;
	    }

	    public void setRa(boolean ra) {
	        this.ra = ra;
	    }

	    public int getRcode() {
	        return rcode;
	    }

	    public void setRcode(int rcode) {
	        this.rcode = rcode;
	    }

	    public boolean isRd() {
	        return rd;
	    }

	    public void setRd(boolean rd) {
	        this.rd = rd;
	    }

	    public boolean isTc() {
	        return tc;
	    }

	    public void setTc(boolean tc) {
	        this.tc = tc;
	    }

	    public int getZ() {
	        return z;
	    }

	    public void setZ(int z) {
	        this.z = z;
	    }

	    public byte[] encode(){
	        return serialize(this);
	    }
	    
	    public static byte[] serialize(Header m){
	    	byte[] result = new byte[12];
	    	int flags = 0;
	    	flags |= (1 << (15 - (m.isQr()?1:0)));
	    	flags &= 0x87FF;
	    	flags |= (m.getOpcode() << 11);
	    	flags |= (1 << (5 - (m.isAa()?1:0)));
	    	flags |= (1 << (6 - (m.isTc()?1:0)));
	    	flags |= (1 << (7 - (m.isRd()?1:0)));
	    	flags |= (1 << (8 - (m.isRa()?1:0)));
	    	//flags |=()
	    	flags &= ~0xF;
	    	flags |= m.getRcode();
	    	return result;
	    }
	    
	    public static Header unserialize(byte[] input){
	        return null;
	    }
}
